package com.sskj.qiangjin.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.bean.UserBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.qiangjin.bean.TxDataBean;
import com.sskj.qiangjin.bean.WithDrawLimitBean;
import com.sskj.qiangjin.http.HttpConfig;
import com.sskj.qiangjin.ui.activity.WithdrawActivity;


public class WithdrawActivityPresenter extends BasePresenter<WithdrawActivity> {
    /**
     * 获取短信验证码---codeType
     * 1注册 2 重置 3 安全验证 4 订单确认通知(标记付款时) 5 订单处理通知(卖给他时) 6排单成功
     *
     * @param mobile 手机号
     * @return
     */
    public void sendCode(String mobile) {
        httpService.sendCode(mobile, "3")
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.sendCodeOk();
                        } else {
                            mView.sendCodeError();
                        }
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        mView.sendCodeError();
                        super.onError(response);
                    }
                });
    }

    /**
     * 提币
     */
    public void withDraw(String code, String address, String price, String tpwd, String pid) {
        httpService.withDraw(code, address, price, tpwd, pid)
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.withDrawSuccess();
                        }
                    }
                });
    }

    /**
     * 提币
     */
    public void withDrawCoin(String code, String price, String tpwd) {
        httpService.withDrawCoin(code, price, tpwd)
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.withDrawSuccess();
                        }
                    }
                });
    }


    //提币条件
    public void getWithDrawLimit() {
        httpService.withDrawLimit()
                .tag(this)
                .execute(new JsonCallBack<HttpData<WithDrawLimitBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<WithDrawLimitBean>> response) {
                        HttpData httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updataWithDrawLimit((WithDrawLimitBean) httpData.getData());
                        } else {
                            ToastUtil.showShort(httpData.msg);
                        }
                    }
                });
    }


    public void getUSDTInfo() {
        httpService.userInfo("cny")
                .tag(this)
                .execute(new JsonCallBack<HttpData<UserBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<UserBean>> response) {
                        HttpData httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            UserBean userBean = (UserBean) httpData.getData();
                            mView.updateQC(userBean);
                        }
                    }
                });
    }

    public void getTxData() {
        httpService.getTxData()
                .tag(this)
                .execute(new JsonCallBack<HttpData<TxDataBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<TxDataBean>> response) {
                        HttpData httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.getTxDataSuccess((TxDataBean) httpData.getData());
                        }
                    }
                });
    }

}
